/**
 * 商品相关API
 */

import { request } from './request';
import type { GoodsItem, GoodsCategory, GoodsListParams } from '../types/goods';

/**
 * 获取商品列表
 */
export const getGoodsList = (params: GoodsListParams) => {
  return request.get<{
    list: GoodsItem[];
    total: number;
    hasMore: boolean;
  }>('/goods/list', params);
};

/**
 * 获取商品详情
 */
export const getGoodsDetail = (id: string) => {
  return request.get<GoodsItem>(`/goods/detail/${id}`);
};

/**
 * 获取商品分类
 */
export const getGoodsCategories = () => {
  return request.get<GoodsCategory[]>('/goods/categories');
};

/**
 * 发布商品
 */
export const publishGoods = (data: Partial<GoodsItem>) => {
  return request.post<{ id: string }>('/goods/publish', data);
};

/**
 * 更新商品
 */
export const updateGoods = (id: string, data: Partial<GoodsItem>) => {
  return request.put<GoodsItem>(`/goods/update/${id}`, data);
};

/**
 * 删除商品
 */
export const deleteGoods = (id: string) => {
  return request.delete(`/goods/delete/${id}`);
};

/**
 * 搜索商品
 */
export const searchGoods = (keyword: string, params?: Partial<GoodsListParams>) => {
  return request.get<{
    list: GoodsItem[];
    total: number;
    hasMore: boolean;
  }>('/goods/search', { keyword, ...params });
};